{
 "metadata": {
  "name": "",
  "signature": "sha256:bc68909e6434b9f437c3ebfcd0696eddeaa967bcf99e461452642bd5982fe393"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "# MTH 9879 Market Microstructure Models,    Spring 2015 \n",
      "\n",
      "## Lecture 3: Inventory models and market-making\n",
      "\n",
      "Tai-Ho Wang    \n",
      "Department of Mathematics   \n",
      "  \n",
      "  \n",
      "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2014/09/BCCUNYstacked_BLK.jpg\" align = \"center\" width=160></h2>  \n",
      "\n",
      "$$\n",
      "\\newcommand{\\bea}{\\begin{eqnarray}}\n",
      "\\newcommand{\\eea}{\\end{eqnarray}}\n",
      "\\newcommand{\\supp}{\\mathrm{supp}}\n",
      "\\newcommand{\\F}{\\mathcal{F} }\n",
      "\\newcommand{\\cF}{\\mathcal{F} }\n",
      "\\newcommand{\\cG}{\\mathcal{G} }\n",
      "\\newcommand{\\E}{\\mathbb{E} }\n",
      "\\newcommand{\\EE}{\\mathbb{E} }\n",
      "\\newcommand{\\Eof}[1]{\\mathbb{E}\\left[ #1 \\right]}\n",
      "\\def\\Cov{{ \\mbox{Cov} }}\n",
      "\\def\\Var{{ \\mbox{Var} }}\n",
      "\\newcommand{\\1}{\\mathbf{1} }\n",
      "\\newcommand{\\p}{\\partial}\n",
      "\\newcommand{\\pt}{\\partial}\n",
      "\\newcommand{\\PP}{\\mathbb{P} }\n",
      "\\newcommand{\\Pof}[1]{\\mathbb{P}\\left[ #1 \\right]}\n",
      "\\newcommand{\\QQ}{\\mathbb{Q} }\n",
      "\\newcommand{\\R}{\\mathbb{R} }\n",
      "\\newcommand{\\DD}{\\mathbb{D} }\n",
      "\\newcommand{\\HH}{\\mathbb{H} }\n",
      "\\newcommand{\\spn}{\\mathrm{span} }\n",
      "\\newcommand{\\cov}{\\mathrm{cov} }\n",
      "\\newcommand{\\HS}{\\mathcal{L}_{\\mathrm{HS}} }\n",
      "\\newcommand{\\Hess}{\\mathrm{Hess} }\n",
      "\\newcommand{\\trace}{\\mathrm{trace} }\n",
      "\\newcommand{\\cL}{\\mathcal{L} }\n",
      "\\newcommand{\\LL}{\\mathcal{L} }\n",
      "\\newcommand{\\s}{\\mathcal{S} }\n",
      "\\newcommand{\\ee}{\\mathcal{E} }\n",
      "\\newcommand{\\ff}{\\mathcal{F} }\n",
      "\\newcommand{\\hh}{\\mathcal{H} }\n",
      "\\newcommand{\\bb}{\\mathcal{B} }\n",
      "\\newcommand{\\dd}{\\mathcal{D} }\n",
      "\\newcommand{\\g}{\\mathcal{G} }\n",
      "\\newcommand{\\half}{\\frac{1}{2} }\n",
      "\\newcommand{\\T}{\\mathcal{T} }\n",
      "\\newcommand{\\bit}{\\begin{itemize}}\n",
      "\\newcommand{\\eit}{\\end{itemize}}\n",
      "\\newcommand{\\beq}{\\begin{equation}}\n",
      "\\newcommand{\\eeq}{\\end{equation}}\n",
      "\\newcommand{\\tr}{\\mbox{tr}}\n",
      "\\newcommand{\\Xv}{X^{(v)}}\n",
      "$$\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "## Outline of Lecture 3\n",
      "\n",
      "* The Garman (1976) model\n",
      "* Amihud and Mendelson (1980)\n",
      "* The Stoll (1978) model\n",
      "* Ho and Stoll (1981)\n",
      "* Dynamic programming principle and the Hamilton-Jacobi-Bellman (HJB) equation\n",
      "* Avellaneda and Stoikov (2008)\n",
      "* Gu&eacute;ant, Lehalle and Fernandez-Tapia (2013)\n",
      "* Guilbaud and Pham (2013)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Garman (1976)\n",
      "\n",
      "* A quote from Garman (1976):\n",
      "    \n",
      "    *We depart from the usual approaches of the theory of exchange by (1) making the assumption of asynchronous, temporally discrete market activities on the part of market agents and (2) adopting a viewpoint which makes the temporal microstructure, i.e., moment-to-moment aggregate exchange behavior, as an important descriptive aspect of such markets.*\n",
      "\n",
      "\n",
      "* Dealers are needed because buyers and sellers don\u2019t arrive synchronously.\n",
      "    * In our context, agents may act as market makers without necessarily being dealers as such."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Garman (1976)\n",
      "\n",
      "- MB orders arrive at rate $\\lambda_A(p)$ and MS orders at rate $\\lambda_B(p)$, both functions of the price $p$.\n",
      "\n",
      "    - $\\lambda_A(p)$ is decreasing in $p$ and $\\lambda_B(p)$ is increasing in $p$.\n",
      "\n",
      "\n",
      "- If the dealer were to quote a choice price, the graphs would cross at $p^\\star$ given by:\n",
      "    $$\n",
      "    \\lambda_A(p^\\star)=\\lambda_B(p^\\star)=:\\lambda^\\star\n",
      "    $$\n",
      "\n",
      "\n",
      "- If instead the dealer quotes a two-way price $\\{B,A\\}$, and on average $\\lambda_A(A)=\\lambda_B(B)=:\\tilde \\lambda$, the P&L per unit of time will be given by\n",
      "    $$\n",
      "    \\pi(B,A)=(A-B)\\,\\tilde \\lambda.\n",
      "    $$\n",
      "\n",
      "    - The wider the spread, the greater the P&L per trade but the lower the rate of trading.\n",
      "    \n",
      "    - The dealer finds the optimal bid and offer by maximizing P&L per unit time.\n",
      "\n",
      "\n",
      "- <font color=red> The two-way price $\\{B,A\\}$ is set once and for all.  </font>\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Garman model schematic\n",
      "\n",
      "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/Garman.png\" align = \"center\" width=500></h2>\n",
      "\n",
      "Figure 1: As the price increases, the rate $\\lambda_B$ of MS increases, the rate $\\lambda_A$ of MB decreases."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Garman (1976)\n",
      "\n",
      "- The dealer needs to hold cash and securities in order to be able to accommodate asynchronous buying and selling.\n",
      "\n",
      "\n",
      "- Garman assumes that the bid $B$ and ask $A$ are set once and for all.  This implies that\n",
      "    - Cash holdings follow a zero-drift random walk.\n",
      "    - Stock holdings follow a zero-drift random walk.\n",
      "\n",
      "\n",
      "- The dealer is ruined with probability one.\n",
      "    - With realistic parameters, he is ruined in a few days!\n",
      "\n",
      "\n",
      "- The main intuition is then <br>\n",
      "    *[Garman] ``The order of magnitude makes it clear that the specialists must pursue a policy of relating their prices to their inventories in order to avoid failure.''*\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Amihud and Mendelson (1980)\n",
      "\n",
      "- Framework similar to Garman.\n",
      "\n",
      "\n",
      "- Inventory is constrained to lie between given lower and upper bounds.\n",
      "\n",
      "\n",
      "- <font color=red> The monopolistic market maker sets two-way price dynamically in order to maximize expected profit per unit time in equilibrium. </font>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Amihud and Mendelson implications\n",
      "\n",
      "- $B$ and $A$ are monotone decreasing functions of inventory.\n",
      "\n",
      "\n",
      "- There is a spread $s = A \u2212 B > 0$.\n",
      "\n",
      "\n",
      "- There is a preferred inventory and $s$ is an increasing function of the distance from this preferred inventory position.\n",
      "\n",
      "\n",
      "- The quotes are not set symmetrically about fair value."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### CARA utility\n",
      "\n",
      "- CARA stands for *Constant Absolute Risk Aversion*.\n",
      "\n",
      "    - The Arrow-Pratt measure of absolute risk-aversion (ARA), a.k.a., the *coefficient of absolute risk aversion*, $A$ of a utility function $U$ is defined as $A = -\\frac{U''}{U'}$.\n",
      "    - Exponential utility $U(x)=\\frac1\\alpha\\left(1-e^{-\\alpha x}\\right)$ is unique in exhibiting constant absolute risk aversion (CARA). Indeed, $A(x) = \\alpha$ for exponential utility.\n",
      "    - Sometimes exponential utility is quoted in the form $U(x) = -e^{-\\alpha\\,x}$.\n",
      "\n",
      "\n",
      "- If $W$ is normally distributed,\n",
      "    $$\n",
      "    \\EE\\left[U(W)\\right]=\\EE\\left[-e^{-\\alpha\\,W}\\right]=-\\exp\\left\\{-\\alpha\\,\\left(\\EE[W]-\\alpha/2\\,\\Var[W]\\right)\\right\\}\n",
      "    $$\n",
      "    so maximizing CARA utility is equivalent to maximizing\n",
      "    $$\n",
      "    \\cL(W)=\\EE[W]-\\frac\\alpha2\\,\\Var[W]\n",
      "    $$\n",
      "    which is just mean-variance optimization.\n",
      "\n",
      "\n",
      "- $\\EE[W]-\\frac\\alpha2\\,\\Var[W]$ is called the *certainty equivalent* of $W$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Stoll (1978)\n",
      "\n",
      "- The dealer has exponential utility:\n",
      "\n",
      "    $$\n",
      "    U(W)=-e^{-\\alpha\\,W}.\n",
      "    $$\n",
      "\n",
      "\n",
      "- Inventory is constrained to lie between given lower and upper bounds.\n",
      "\n",
      "\n",
      "- The security has the random payoff $S \\sim N(\\mu, \\sigma^2)$.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Stoll (1978) optimal bid-ask computation\n",
      "\n",
      "- Suppose the dealer's current inventory is $q$.\n",
      "\n",
      "\n",
      "- He posts a bid at $B$.\n",
      "    - If his bid is not hit, his terminal wealth will be $W=q\\,S$.\n",
      "    - If his bid is hit, his terminal wealth will be $W=(q+1)S-B$.\n",
      "\n",
      "\n",
      "- For the dealer to be indifferent, we must have\n",
      "    \n",
      "    $$\n",
      "    \\EE[U\\left((q+1)S-B\\right)]=\\EE[U(q\\,S)]\n",
      "    $$\n",
      "    \n",
      "    so\n",
      "    \n",
      "    <a name=\"eq:indifference\"></a>(1)\n",
      "    $$ \n",
      "    (q+1)\\EE[S]-B-\\frac{\\alpha}{2}\\,\\Var[(q+1)\\,S]=q\\,\\EE[S]-\\frac{\\alpha}{2}\\,\\Var[q\\,S]\n",
      "    $$\n",
      "    \n",
      "    Then\n",
      "    \n",
      "    <a name=\"eq:StollBid\"></a>(2)\n",
      "    $$ \n",
      "    B=\\mu-\\frac{\\alpha}{2}\\,\\left[(q+1)^2-q^2\\right]\\,\\sigma^2=\\mu-\\frac{\\alpha}{2}\\,(2\\,q+1)\\,\\sigma^2.\n",
      "    $$\n",
      "\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Stoll (1978) optimal inventory\n",
      "\n",
      "- This indifference price argument works only if the dealer starts with optimal inventory.\n",
      "    - What is his optimal inventory? \n",
      "\n",
      "\n",
      "- Suppose that the current market price of the stock is $P$. \n",
      "\n",
      "\n",
      "- Terminal wealth is then $q\\,(S-P)$.\n",
      "\n",
      "\n",
      "- Maximizing expected terminal utility over $q$ then gives optimal inventory:\n",
      "    $$\n",
      "    \\frac{d}{dq}\\,\\left\\{q\\,(\\mu-P)-\\frac{\\alpha}{2}\\,q^2\\,\\sigma^2\\right\\}=0\n",
      "    $$\n",
      "    when\n",
      "    $$\n",
      "    q=\\frac{\\mu-P}{\\alpha\\,\\sigma^2}=:q^\\star\n",
      "    $$\n",
      "\n",
      "\n",
      "- Substituting back into [(2)](#eq:StollBid) gives\n",
      "\n",
      "    <a name=\"eq:StollBidOptimal\"></a>(3) \n",
      "    $$ \n",
      "    B=P-\\alpha\\,\\frac{\\sigma^2}{2}.\n",
      "    $$\n",
      "    \n",
      "\n",
      "- Similarly, the ask price is given by \n",
      "\n",
      "    $$\n",
      "    A = P + \\alpha\\,\\frac{\\sigma^2}{2}.\n",
      "    $$\n",
      "\n",
      "\n",
      "#### Note\n",
      "\n",
      "* Bid and ask are symmetric around the current price $P$ and is independent of $\\mu$.\n",
      "\n",
      "* Spread is equal to $\\alpha \\sigma^2$. The more risk averse the market maker is or the more volalitle the security is, the wider the spread.\n",
      "\n",
      "* <font color=blue> Spread is quadratic in volaility. </font>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Extension to $n$ assets\n",
      "\n",
      "- In the $n$ asset case, we can make the same indifference price argument to derive the optimal bids and offers.\n",
      "    - Assume the joint distribution of the payoffs of the $n$ assets is multivariate normal.\n",
      "\n",
      "\n",
      "- The analog of equation [(1)](#eq:indifference) for finding the optimal bid $B_j$ for asset $j$ is\n",
      "\n",
      "    <a name=\"eq:indifferenceN\"></a>(4) \n",
      "    \\begin{eqnarray*}\n",
      "    &&\\sum_i^n\\,q_i\\,\\mu_i+\\mu_j-B_j-\\frac{\\alpha}{2}\\,\\Var\\left[\\sum_i^n\\,q_i\\,S_i+S_j\\right]\n",
      "    = \\sum_i^n\\,q_i\\,\\mu_i-\\frac{\\alpha}{2}\\,\\Var\\left[\\sum_i^n\\,q_i\\,S_i\\right]\n",
      "    \\end{eqnarray*}\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "This gives\n",
      "\n",
      "<a name=\"eq:null\"></a>(5) \n",
      "\\begin{eqnarray}\n",
      "B_j&=&\\mu_j-\\alpha\\,\\sum_i^n\\,q_i\\,\\Cov\\left[S_i,S_j\\right]-\\frac{\\alpha}{2}\\,\\Var[S_j]\\nonumber\\\\\n",
      "&=&\\mu_j-\\alpha\\,\\sum_i^n\\,q_i\\,\\rho_{ij}\\,\\sigma_i\\,\\sigma_j\n",
      "-\\frac{\\alpha}{2}\\,\\sigma_j^2.\n",
      "\\end{eqnarray}\n",
      "\n",
      "Extending further to a quote in size $n_j$, we see that\n",
      "\n",
      "<a name=\"eq:StollBidOptimalN\"></a>(6) \n",
      "$$\n",
      "B_j=\\mu_j-\\alpha\\,\\sum_i^n\\,q_i\\,\\rho_{ij}\\,\\sigma_i\\,\\sigma_j\n",
      "-\\frac{\\alpha}{2}\\,n_j\\,\\sigma_j^2\n",
      "$$\n",
      "\n",
      "A completely analogous argument gives the fair ask price\n",
      "\n",
      "$$\n",
      "A_j=\\mu_j - \\alpha\\,\\sum_i^n\\,q_i\\,\\rho_{ij}\\,\\sigma_i\\,\\sigma_j + \\frac{\\alpha}{2}\\,n_j\\,\\sigma_j^2\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Observations\n",
      "\n",
      "From equation [(6)](#eq:StollBidOptimalN), we note that\n",
      "\n",
      "- The optimal bid for the $j$th asset depends in general on existing positions in all other assets.\n",
      "\n",
      "\n",
      "- Assuming the correlations $\\rho_{ij}$ are positive, the greater the initial inventory, the lower the bid is biased.\n",
      "    - The lower the correlation with existing inventory, the less the quote bias.\n",
      "\n",
      "\n",
      "- The spread\n",
      "    $$\n",
      "    s_j=A_j-B_j=\\alpha\\,n_j\\,\\sigma_j^2\n",
      "    $$\n",
      "    is\n",
      "    \n",
      "    - Increasing in the risk aversion coefficient (price of risk) $\\alpha$.\n",
      "    - Increasing in the asset volatility $\\sigma_j$.\n",
      "    - Increasing in the quote size $n_j$.\n",
      "\n",
      "\n",
      "- The spread does not depend on inventory.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Choice of risk measure\n",
      "\n",
      "- Mean-variance optimization is equivalent to adopting variance as a risk measure.\n",
      "    - The units ($\\$^2$) are wrong: We don't think that double the position has four times the risk!\n",
      "\n",
      "\n",
      "- Suppose we take value-at-risk (VaR) as our risk measure instead.\n",
      "    - This choice of risk measure is more consistent with allocated cost of capital in reality.\n",
      "\n",
      "\n",
      "- The analog of [(4)](#eq:indifferenceN) for a quote of size $m$ is\n",
      "    \\begin{eqnarray*}\n",
      "    &&\\sum_i^n\\,q_i\\,\\mu_i+m\\,(\\mu_j-B_j)-\\nu\\,\\sqrt{\\Var\\left[\\sum_i^n\\,q_i\\,S_i+m\\,S_j\\right]}\\nonumber\\\\\n",
      "    &=&\\sum_i^n\\,q_i\\,\\mu_i-\\nu\\,\\sqrt{\\Var\\left[\\sum_i^n\\,q_i\\,S_i\\right]}.\n",
      "    \\end{eqnarray*}\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Rearranging gives\n",
      "\n",
      "<a name=\"eq:VaRbid\"></a>(7) \n",
      "$$\n",
      "B_j=\\mu_j-\\frac{\\nu}{m}\\,\\left\\{\\sqrt{\\Var\\left[\\sum_i^n\\,q_i\\,S_i+m\\,S_j\\right]}\n",
      "-\\sqrt{\\Var\\left[\\sum_i^n\\,q_i\\,S_i\\right]}\\right\\}\n",
      "$$\n",
      "\n",
      "To get intuition for this expression, consider the one-stock case where there is existing inventory $q$.  The optimal bid is then\n",
      "\n",
      "$$\n",
      "B=\\mu - \\frac \\nu m\\,\\sigma\\left\\{ |q+m| - |q|\\right\\}=\\mu - \\frac \\nu m\\,\\sigma\\,\\left\\{\\begin{array}{ll}\n",
      "m & \\text{ if } q \\geq 0\\\\\n",
      "2\\,q + m & \\text{ if } -m \\leq q <  0\\\\\n",
      "- m & \\text{ if } q  < -m .\n",
      "\\end{array}\n",
      "\\right.\n",
      "$$\n",
      "\n",
      "- If the potential trade is not risk reducing, the quoted spread is linear in the volatility $\\sigma$ and (approximately) independent of the quoted size $m$.\n",
      "    - <font color=blue> Spread is linear in volatility both in previous models and empirically. </font>\n",
      "    - Intuitively, quoted spread should somewhat depend on quoted size in dealer markets (but it may be independent of size over a large range of sizes).\n",
      "    - Note also that $\\nu$ is dimensionless.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Monetary risk measures\n",
      "\n",
      "Let $\\mathcal{X}$ denote the set of all financial positions.\n",
      "<br>\n",
      "\n",
      "\n",
      "The following definition is from [F\u00f6lmer and Schied]<sup id=\"cite_ref-FS\" class=\"reference\"><a href=\"#cite_note-FS\">[2]</a></sup>:\n",
      "\n",
      "#### Definition (4.1)\n",
      "\n",
      "A mapping $\\rho: \\mathcal{X} \\to \\mathbb{R}$ is called a *monetary risk measure* if it satisfies the following conditions for all $X,Y \\in \\mathcal{X}$:\n",
      "\n",
      "- *Monotonicity*: If $X \\leq Y$, then $\\rho(X) \\geq \\rho(Y)$.\n",
      "- *Cash invariance*: If $m \\in \\mathbb{R}$, then $\\rho(X+m) = \\rho(X) - m$.\n",
      "\n",
      "#### Note\n",
      "\n",
      "- Without loss of generality, we could have $\\rho(0)=0$.\n",
      "- Obviously, variance does not qualify as a monetary risk measure."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Ho and Stoll (1981)\n",
      "\n",
      "- Ho and Stoll extend Stoll (1978) to a multiperiod framework.\n",
      "    - Both order flow and stock price are stochastic.\n",
      "\n",
      "\n",
      "- The log-stock price $x_t$ is modeled as Brownian motion with drift.\n",
      "\n",
      "\n",
      "- Market order arrivals are Poisson with rates $\\lambda_B$ and $\\lambda_A$.  These rates depend linearly on the bid and ask prices $B$ and $A$ set by the dealer.\n",
      "\n",
      "\n",
      "- Inventory has a stochastic evolution in addition to its natural evolution resulting from the arrival of market orders.\n",
      "\n",
      "\n",
      "- The dealer's utility function is quadratic.\n",
      "\n",
      "\n",
      "- The solution to this problem involves stochastic optimal control techniques and in fact, this specific problem seems to be too hard to solve in closed-form.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Review: Feynman-Kac formula\n",
      "\n",
      "The solution of the PDE \n",
      "\n",
      "$$\n",
      "u_t + \\frac{\\sigma^2(x,t)}2 u_{xx} + \\mu(x,t) u_x + h(x,t) = 0\n",
      "$$\n",
      "\n",
      "with terminal condition \n",
      "\n",
      "$$\n",
      "u(x,T) = g(x)\n",
      "$$\n",
      "\n",
      "has the stochastic representation \n",
      "\n",
      "\\begin{eqnarray*}\n",
      "u(x,t) = \\Eof{\\left. g(X_T) + \\int_t^T h(X_s,s) ds \\right| X_t = x},\n",
      "\\end{eqnarray*}\n",
      "\n",
      "where $X_t$ is the diffusion process satisfying the SDE\n",
      "\n",
      "$$\n",
      "dX_t = \\mu(X_t,t) dt + \\sigma(X_t,t) dW_t.\n",
      "$$\n",
      "\n",
      "$W_t$ is a Brownian motion. \n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Stochastic control problem\n",
      "\n",
      "A stochastic control problem is a control problem which aims to maximize certain expected rewards among all admissible controls. <br>\n",
      "Specifically, consider\n",
      "\n",
      "$$\n",
      "  \\max_{v\\in\\cG[0,T]} \\E\\left[g(\\Xv_T) + \\int_0^T h(s,\\Xv_s,v_s) ds \\right]\n",
      "$$\n",
      "\n",
      "where\n",
      "\n",
      "* $g$ is referred to as the *terminal reward* and $h$ is the *running reward*\n",
      "\n",
      "\n",
      "* the state variable $\\Xv_t$ is driven by the controlled SDE\n",
      "\n",
      "    $$\n",
      "      d\\Xv_t = \\mu( t,\\Xv_t, v_t) dt + \\sigma(t,\\Xv_t, v_t) dW_t.\n",
      "    $$\n",
      "    \n",
      "\n",
      "* $\\cG[0,T]$ is the collection of admissible controls in the time interval $[0,T]$ "
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Bellman's principle of optimality\n",
      "\n",
      "\"An optimal policy has the property that whatever the initial state and initial decision are, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision.\"\n",
      "\n",
      "<br> (See Bellman, 1957, Chap. III.3.)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Value function \n",
      "\n",
      "* For a given admissible control $v\\in\\cG[t,T]$, define the expected objective functional $J^{(v)}$ as\n",
      "    \n",
      "    $$\n",
      "      J^{(v)}(t,x) = \\E\\left[\\left. g(\\Xv_T) + \\int_0^T h(s,\\Xv_s,v_s) ds \\right| \\cF_t \\right].\n",
      "    $$\n",
      "\n",
      "* The value function $J(t,x)$ for a stochastic control problem is defined as\n",
      "\n",
      "    $$\n",
      "      J(t,x) = \\max_{v\\in\\cG[t,T]} J^{(v)}(t,x).\n",
      "    $$\n",
      "\n",
      "\n",
      "* The value function $J$ at $(t,x)$ is the optimal value of the control problem conditioned on the process starting at $(t,x)$ and applying the optimal control thereafter."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Bellman's principle again\n",
      "\n",
      "The Bellman's principle can be rephrased in terms of value function as follow. For any $0 < \\epsilon < T -t$,\n",
      "\n",
      "$$\n",
      "J(t,x) = \\max_{v\\in\\cG[t,t+\\epsilon]} \\E\\left[\\left. \\int_t^{t+\\epsilon} h(s,\\Xv_s,v_s) ds + J(t+\\epsilon,\\Xv_{t+\\epsilon}) \\right| \\cF_t \\right].\n",
      "$$\n",
      "\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### The Hamilton-Jacobi-Bellman (HJB) equation\n",
      "\n",
      "The value function $J$ satisfies the terminal value problem\n",
      "\n",
      "$$\n",
      "\\p_t J(t,x) + \\max_{v\\in\\cG[t]} \\{\\cL^{(v)} J(t,x) + h(t,x,v) \\} = 0, \\mbox{ for } t < T\n",
      "$$\n",
      "\n",
      "with terminal condition\n",
      "\n",
      "$$\n",
      "  J(T,x) = g(x).\n",
      "$$\n",
      "\n",
      "#### Note\n",
      "\n",
      "* The HJB equation is bascially an infinitesimal version of the Bellman's principle. \n",
      "\n",
      "* The optimal policy (control) is given implicitly in terms of the value function $J$.\n",
      "\n",
      "* The whole argument is applicable to processes with jump as well. \n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Ho and Stoll setup\n",
      "\n",
      "- The dealer quotes prices\n",
      "    $$\n",
      "    p_b = p-b; \\quad p_a = p+a\n",
      "    $$\n",
      "\n",
      "\n",
      "- Cash:\n",
      "    $$\n",
      "    dF = r\\,F \\,dt - (p-b)\\,dq_b+(p+a)\\,dq_a\n",
      "    $$\n",
      "\n",
      "\n",
      "- Stock:\n",
      "    $$\n",
      "    dX = r_X\\,X\\,dt +\\sigma_X\\,X\\,dZ_X\n",
      "    $$\n",
      "\n",
      "\n",
      "- Inventory:\n",
      "    $$\n",
      "    dI = r_I\\,I\\,dt + p\\,dq_b - p \\,dq_a +I\\,\\,\\sigma_I\\,dZ_I\n",
      "    $$\n",
      "    where $dq_a$ and $dq_b$ represent Poisson distributed jumps with intensities $\\lambda_a$, $\\lambda_b$.\n",
      "\n",
      "\n",
      "- Base wealth:\n",
      "    $$\n",
      "    dY = r_Y\\,Y\\,dt+Y\\,dZ_Y\n",
      "    $$\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Ho and Stoll objective and value function \n",
      "\n",
      "* The dealer's objective is to maximize the expected terminal utility of wealth, i.e., \n",
      "\n",
      "    $$\n",
      "    \\max_{a,b \\in \\cG} \\EE\\left[U(F_T + I_T + Y_T)\\right]\n",
      "    $$ \n",
      "\n",
      "\n",
      "* Since there is no intermediate running reward $h(\\cdot)$, the value function $J(t,f,i,y)$ reduces to\n",
      "\n",
      "    $$\n",
      "    J(t,f,i,y) = \\max_{a,b \\in \\mathcal{G}[t,T]} \\Eof{\\left.U(F_T,I_T,Y_T)\\right|F_t=f,Y_t = y,I_t = i}.\n",
      "    $$\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### HJB equation for Ho and Stoll value function\n",
      "\n",
      "Ignoring interest rates and returns (which are effectively irrelevant for small times), we get\n",
      "\n",
      "\\begin{eqnarray*}\n",
      "&&\\frac{\\partial J}{\\partial t}+\\mathcal{L}_t \\,J + \\max_{a,b \\in\\mathcal{G}}\\,\\left\\{\\lambda_a\\,\\left[J(t,F+p\\,Q +a\\,Q, I-p\\,Q,Y)-J(t,F,I,Y)\\right]\\right.\\\\\n",
      "&&\\quad\\quad\\quad+\n",
      "\\left.\n",
      "\\lambda_b\\,\\left[J(t,F-p\\,Q +b\\,Q, I+p\\,Q,Y)-J(t,F,I,Y)\\right]\\right\\}=0\n",
      "\\end{eqnarray*}\n",
      "\n",
      "where $\\mathcal{L}_t$ is the infinitesimal generator of the It&ocirc; diffusion:\n",
      "\n",
      "$$\n",
      "\\mathcal{L}_t = \\frac{1}{2}\\,\\sigma_Y^2\\,Y^2\\,\\partial_{Y,Y}+ \\frac{1}{2}\\,\\sigma_I^2\\,I^2\\,\\partial_{I,I}+ \\sigma_Y\\,\\sigma_I\\,Y\\,I\\,\\partial_{Y,I}\n",
      "$$\n",
      "\n",
      "- Not surprisingly, this equation is near impossible to solve, even approximately.\n",
      "\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Conclusions of Ho and Stoll (1981)\n",
      "\n",
      "- The spread depends on the time horizon of the dealer.\n",
      "    - The shorter the time remaining, the lower the risk - this is somewhat artificial!\n",
      "\n",
      "\n",
      "- The risk adjustment is increasing in both the risk aversion $\\alpha$ and the variance $\\sigma^2$.\n",
      "\n",
      "\n",
      "- The spread is independent of inventory level.\n",
      "    - The dealer moves his mid-price depending on inventory so as to influence the arrival rates of MB and MS orders.\n",
      "\n",
      "\n",
      "- All of this is consistent with the Stoll (1978) conclusions.\n",
      "\n",
      "\n",
      "- Also, MB orders cause the mid-price to increase, MS orders cause the mid-price to decrease; there is market impact.\n",
      "\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Avellaneda and Stoikov (2008)\n",
      "\n",
      "- As in Stoll (1978), the agent's utility is exponential.\n",
      "\n",
      "\n",
      "- Stock price follows arithmetic Brownian motion\n",
      "    $$\n",
      "    dS=\\sigma\\,dW\n",
      "    $$\n",
      "\n",
      "\n",
      "- Consider first the \"frozen inventory limit\" where the agent holds inventory $q$ until time $T$ without trading.\n",
      "\n",
      "\n",
      "- Wlog, take initial wealth to be $x$.  Then the expected utility $U$ for froze inventory at time $t$ is\n",
      "    \\begin{eqnarray*}\n",
      "    U(t,x,S,q)&=&-e^{-\\alpha\\,x}\\,\\EE_t\\left[e^{-\\alpha\\,q\\,S_T}\\right]\\\\\n",
      "    &=&-e^{-\\alpha\\,x}\\,e^{-\\alpha\\,q\\,S}\\,\\exp\\left\\{\\frac{\\alpha^2\\,q^2\\,\\sigma^2\\,(T-t)}{2}\\right\\}\\\\\n",
      "    &=:&-e^{V(t,x,S,q)}\n",
      "    \\end{eqnarray*}\n",
      "    where $x$ is initial wealth and $q$ is inventory.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Reservation bid price\n",
      "\n",
      "The reservation bid price $r_B$ solves\n",
      "\n",
      "$$\n",
      "V(t,x-r_B,S,q+1)=V(t,x,S,q).\n",
      "$$\n",
      "\n",
      "The solution, again as in Stoll, is\n",
      "\n",
      "$$\n",
      "r_B(t,x,S,q) = S - \\frac{\\alpha}{2}\\,(2\\,q+1)\\,\\sigma^2\\,(T-t)\n",
      "$$\n",
      "\n",
      "Similarly, the reservation ask price $r_A$ is given as\n",
      "\n",
      "$$\n",
      "r_A(t,x,S,q) = S + \\frac{\\alpha}{2}\\,(-2\\,q+1)\\,\\sigma^2\\,(T-t)\n",
      "$$\n",
      "\n",
      "The average of the reservation bid and ask prices\n",
      "\n",
      "<a name=\"eq:reservationPrice\"></a>(8) \n",
      "$$\n",
      "r^\\star= \\frac{r_A + r_B}2=S-\\alpha\\,q\\,\\sigma^2\\,(T-t)\n",
      "$$\n",
      "\n",
      "is referred to as the *reservation price*."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Model setup\n",
      "\n",
      "- The MB arrival rate $\\lambda^A$ is decreasing in $\\delta^A=A-S$.\n",
      "\n",
      "\n",
      "- The MS arrival rate $\\lambda^B$ is decreasing in $\\delta^B=S-B$.\n",
      "\n",
      "\n",
      "- Wealth in cash jumps every time there is a market order:\n",
      "    $$\n",
      "    dx_t = A\\,dN^A_t - B\\,dN^B_t = (S_t + \\delta^A) dN^A_t - (S_t - \\delta^B) dN^B_t \n",
      "    $$\n",
      "\n",
      "\n",
      "- Stock inventory at time $t$ is given by:\n",
      "    $$\n",
      "    q_t=N^B_t-N^A_t\n",
      "    $$\n",
      "    \n",
      "    - Inventory thus depends only on arrivals of market orders and does not have any additional random component.  This considerably simplifies the analysis relative to Ho and Stoll.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Objective and value function \n",
      "\n",
      "* The objective of the dealer is to maximize\n",
      "\n",
      "    $$\n",
      "    \\max_{\\delta^B,\\delta^A}\\EE\\left[-e^{-\\alpha\\,(x_T+q_T\\,S_T)}\\right]\n",
      "    $$\n",
      "    \n",
      "    where the optimal controls $\\delta^B$ and $\\delta^A$ are in general time and state dependent.\n",
      "\n",
      "\n",
      "* The value function of the stochastic control problem is therefore defined by\n",
      "\n",
      "    $$\n",
      "    J(t,x,S,q) = \\max_{(\\delta^B,\\delta^A) \\in \\cG[t,T]} \\EE\\left[\\left. -e^{-\\alpha\\,(x_T+q_T\\,S_T)} \\right|x_t = x, S_t = S, q_t = q \\right]\n",
      "    $$\n",
      "    \n",
      "    where $\\cG[t,T]$ denotes the admissible controls in the time interval $[t,T]$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### It&ocirc;'s formula for processes with jump \n",
      "\n",
      "Let $X_t$ and $Y_t$ be processes with jump. Denote by $X^c_t$ and $Y^c_t$ the continuous part of $X$ and $Y$ respectively. \n",
      "\n",
      "If $J$ is a smooth function, then for $t < s$, we have the following It&ocirc;'s formula \n",
      "\n",
      "\\begin{eqnarray*}\n",
      "&& J(s,x_s,S_s,q_s) - J(t,x_t,S_t,q_t) \\\\\n",
      "&=& \\int_t^s J_t d\\tau + \\int_t^s J_x dx_\\tau^c + \\int_t^s J_S dS_\\tau^c + \\int_t^s J_q dq_\\tau^c \\\\\n",
      "&& + \\frac12 \\int_t^s J_{xx} d[x^c]_\\tau + \\frac12 \\int_t^s J_{SS} d[S^c]_\\tau + \\frac12 \\int_t^s J_{qq} d[q^c]_\\tau + \\mbox{covariation terms} \\\\\n",
      "&& + \\sum_{t < \\tau \\leq s} J(\\tau,x_\\tau,S_\\tau,q_\\tau) - J(\\tau, x_{\\tau-},S_{\\tau-},q_{\\tau-})\n",
      "\\end{eqnarray*}"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### The HJB equation \n",
      "\n",
      "The value function $J(\\cdot)$ satisfies the HJB equation\n",
      "\n",
      "<a name=\"eq:HJBAS\"></a>(9) \n",
      "\\begin{eqnarray*}\n",
      "&&\\pt_t J+\\frac{\\sigma^2}{2}\\,\\pt_S^2 J \\\\\n",
      "&& + \\max_{\\delta^B}\\,\\lambda^B(\\delta^B)\\,\\left[J(t,x - S + \\delta^B, S, q+1)-J(t,x,S,q)\\right] \\\\\n",
      "&& + \\max_{\\delta^A}\\,\\lambda^A(\\delta^A)\\,\\left[J(t,x + S + \\delta^A, S, q-1)-J(t,x,S,q)\\right] \\\\\n",
      "&& = 0\n",
      "\\end{eqnarray*}\n",
      "\n",
      "with terminal condition\n",
      "\n",
      "$$\n",
      "J(T,x,S,q) = -e^{-\\alpha(x + q S)}.\n",
      "$$\n",
      "\n",
      "Because utility is exponential, we can simplify [(9)](#eq:HJBAS) with the ansatz\n",
      "\n",
      "$$\n",
      "J(t,x,S,q,t) = -e^{-\\alpha\\,x}\\,e^{-\\alpha\\,\\theta(t,S,q)}\n",
      "$$\n",
      "\n",
      "#### Note\n",
      "$B = S - \\delta_B$ and $A = S + \\delta_A$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Note that from the ansatz we have\n",
      "\n",
      "\\begin{eqnarray*}\n",
      "&& J(t,x + A,S,q-1) = e^{-\\alpha(x+A) - \\alpha\\theta(t,S,q-1)} = e^{-\\alpha(x+r_A+A - r_A) - \\alpha\\theta(t,S,q-1)} \\\\\n",
      "&=& e^{-\\alpha\\,(A-r_A)} e^{-\\alpha(x + r_A) - \\alpha\\theta(t,S,q-1)} \\\\\n",
      "&=& e^{-\\alpha\\,(A-r_A)} J(t, x + r_A, S, q-1) \\\\\n",
      "&=& e^{-\\alpha\\,(A-r_A)} J(t,x,S,q),\n",
      "\\end{eqnarray*}\n",
      "\n",
      "where in the last equality, we used the definition of reservation price \n",
      "\n",
      "$$\n",
      "J(t,x+r_A,S,q-1,t)=J(t,x,S,q).\n",
      "$$\n",
      "\n",
      "Then\n",
      "\n",
      "$$\n",
      "J(t,x+A,S,q-1) - J(t,x,S,q,t) = J(t,x,S,q)\\,\\left[e^{-\\alpha\\,(A-r_A)}-1\\right].\n",
      "$$\n",
      "\n",
      "Similarly, \n",
      "\n",
      "$$\n",
      "J(t,x-B,S,q+1) - J(t,x,S,q,t) = J(t,x,S,q)\\,\\left[e^{-\\alpha\\,(-B+r_B)}-1\\right].\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Hence, the HJB equation [(9)](#eq:HJBAS) reduces to \n",
      "\n",
      "<a name=\"eq:HJBAS-reduced\"></a>(9') \n",
      "\\begin{eqnarray*}\n",
      "&&\\pt_t J+\\frac{\\sigma^2}{2}\\,\\pt_S^2 J + J(t,x,S,q)\\left\\{\\max_{\\delta^B}\\,\\lambda^B(\\delta^B)\\,\\left[e^{-\\alpha(A-r_A)} - 1 \\right] + \\max_{\\delta^A}\\,\\lambda^A(\\delta^A)\\,\\left[e^{-\\alpha(-B + r_B)} - 1 \\right] \\right\\} = 0\n",
      "\\end{eqnarray*}\n",
      "\n",
      "Substituting the ansatz\n",
      "\n",
      "$$\n",
      "J(t,x,S,q,t)=-e^{-\\alpha\\,x}\\,e^{-\\alpha\\,\\theta(t,S,q)}\n",
      "$$\n",
      "\n",
      "back into the reduced HJB equation [(9')](#eq:HJBAS-reduced) gives the following equation for $\\theta(\\cdot)$:\n",
      "\n",
      "<a name=\"eq:HJBAS2\"></a>(10) \n",
      "\\begin{eqnarray*}\n",
      "&&\\pt_t \\theta+\\frac{\\sigma^2}{2}\\,\\pt_S^2 \\theta-\\alpha\\,\\frac{\\sigma^2}{2}\\,(\\pt_{S}\\theta)^2 \n",
      "+ \\frac 1\\alpha\\,\\max_{\\delta^B}\\,\\lambda^B(\\delta^B)\\,\\left[1-e^{-\\alpha\\,(-B+r_B)}\\right] \n",
      "+ \\frac 1\\alpha\\,\\max_{\\delta^A}\\,\\lambda^A(\\delta^A)\\,\\left[1-e^{-\\alpha\\,(A-r_A)}\\right]\n",
      "= 0\n",
      "\\end{eqnarray*}\n",
      "\n",
      "with boundary condition\n",
      "\n",
      "$$\n",
      "\\theta(T,S,q) = q\\,S.\n",
      "$$\n",
      "\n",
      "#### Note\n",
      "$r_A$ and $r_B$ are independent of $x$. Indeed, $r_B = \\theta(t,S,q+1) - \\theta(t,S,q)$ and $r_A = \\theta(t,S,q) - \\theta(t,S,q-1)$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "The first order condition for the bid price $B$ is then\n",
      "\n",
      "$$\n",
      "\\partial_B \\left\\{\\lambda_B(S-B)\\,\\left[e^{-\\alpha\\,(-B+r_B)}-1\\right]\\right\\}=0\n",
      "$$\n",
      "\n",
      "which gives the implicit relation\n",
      "\n",
      "$$\n",
      "-\\lambda_B'(S-B)\\,\\left[e^{-\\alpha\\,(-B+r_B)}-1\\right]+\\alpha\\,\\lambda^B(S-B)\\,e^{-\\alpha\\,(-B+r_B)}=0\n",
      "$$\n",
      "\n",
      "which may be further simplified to\n",
      "\n",
      "<a name=\"eq:optimalBid\"></a>(11) \n",
      "$$\n",
      "B = r_B - \\frac{1}{\\alpha}\\,\\log\\left(1 - \\alpha\\,\\frac{{\\lambda_B}(S-B)}{\\lambda_B'(S-B)}\\right).\n",
      "$$\n",
      "\n",
      "Similarly, the optimal ask price is given by\n",
      "\n",
      "<a name=\"eq:optimalAsk\"></a>(12) \n",
      "$$\n",
      "A = r_A+\\frac{1}{\\alpha}\\,\\log\\left(1-\\alpha\\,\\frac{{\\lambda_A}(A-S)}{\\lambda_A'(A-S)}\\right).\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Discussion\n",
      "\n",
      "- Equations [(11)](#eq:optimalBid) and [(12)](#eq:optimalAsk) set optimal bid and ask levels as a function of inventory $q$ and the arrival rate function $\\lambda(\\cdot)$.\n",
      "\n",
      "\n",
      "- Optimal bid and ask prices are obtained in two steps:\n",
      "    - Find the reservation prices $r_B$ and $r_A$.\n",
      "    - Adjust these to the current best estimates of the market order arrival rate functions."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Estimating order arrival rates\n",
      "\n",
      "Following Avellaneda and Stoikov again, we may estimate the $\\lambda(\\cdot)$ as follows:\n",
      "\n",
      "- Assume that the density of market order size is   \n",
      "    $$\n",
      "    f(x) \\propto \\frac{1}{x^{1+\\nu}}.\n",
      "    $$\n",
      "    It is a stylized fact that $\\nu \\approx 3/2$.\n",
      "\n",
      "\n",
      "- Assume that market impact is given roughly by\n",
      "    $$\n",
      "    \\Delta p \\propto x^\\beta\n",
      "    $$\n",
      "    where $x$ is order size.  Another stylized fact is that $\\beta \\sim 1/2$.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Let $\\delta$ be distance from the best quote and assume that order arrival rates are constant in aggregate.  Then the rate of arrival of market orders at $\\delta$ can be (handwavingly) estimated as:\n",
      "\n",
      "\\begin{eqnarray*}\n",
      "\\lambda(\\delta) &\\approx& \\Pr(\\Delta p > \\delta)\\\\\n",
      "&\\propto &\\Pr(x > \\delta^{1/\\beta})\\\\\n",
      "&\\propto &\\int_{\\delta^{1/\\beta}}^\\infty\\,\\frac{dx}{x^{1+\\nu}}\\\\\n",
      "&=&\\frac{1}{\\nu}\\,\\delta^{-\\nu/\\beta}\n",
      "\\end{eqnarray*}\n",
      "\n",
      "Substituting $\\nu=3/2$ and $\\beta=1/2$ gives\n",
      "\n",
      "$$\n",
      "\\lambda(\\delta) \\sim \\frac{1}{\\delta^3}\n",
      "$$\n",
      "\n",
      "This is nothing other than the famous cubic law of [Gabaix et al.]<sup id=\"cite_ref-GabaixEtAl\" class=\"reference\"><a href=\"#cite_note-GabaixEtAl\">[3]</a></sup>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Then\n",
      "\n",
      "$$\n",
      "\\frac{\\lambda'(\\delta)}{\\lambda(\\delta)} \\approx -\\frac{3}{\\delta}\n",
      "$$\n",
      "\n",
      "and recalling that $B=S-\\delta_B$, we get\n",
      "\n",
      "\\begin{eqnarray*}\n",
      "B&=&r_B-\\frac{1}{\\alpha}\\,\\log\\left(1 - \\alpha\\,\\frac{{\\lambda_B}(S-B)}{\\lambda_B'(S-B)}\\right)\\\\\n",
      "&=&r_B-\\frac{1}{\\alpha}\\,\\log\\left(1 + \\alpha\\,\\frac{\\delta_B}3\\right)\\\\\n",
      "&\\approx & r_B - \\frac{\\delta_B}3\n",
      "\\end{eqnarray*}\n",
      "\n",
      "Similarly, $A \\approx r_A + \\frac{\\delta_A}3$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Infinite horizon objective\n",
      "\n",
      "- The reservation price [(8)](#eq:reservationPrice) depends explicitly on time because it relates to the variance of the payoff at some final time.\n",
      "\n",
      "\n",
      "- For a market-making business, (we hope) there is no final time.  Avellaneda and Stoikov suggest considering an expected cumulative utility of the form\n",
      "\n",
      "    \\begin{eqnarray*}\n",
      "    U(x,S,q)&=&\\EE\\left[-\\int_0^\\infty\\,e^{-\\omega\\,t}\\,e^{-\\alpha\\,(x+q\\,S_t)}\\,dt\\right]\\\\\n",
      "    &=&-e^{-\\alpha\\,(x+q\\,S)}\\,\\int_0^\\infty\\,e^{-(\\omega-\\alpha^2\\,q^2\\,\\sigma^2/2)\\,t}\\,dt\\\\\n",
      "    &=&-\\frac{e^{-\\alpha\\,(x+q\\,S)}}{\\omega-\\alpha^2\\,q^2\\,\\sigma^2/2}\n",
      "    \\end{eqnarray*}\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Infinite horizon reservation price\n",
      "\n",
      "Now with the expected cumulative utility $U(\\cdot)$ at hand, we can apply the definition of reservation price $r_B$:\n",
      "\n",
      "$$\n",
      "U(x-r_B,S,q+1) = U(x,S,q)\n",
      "$$\n",
      "\n",
      "to obtain\n",
      "\n",
      "<a name=\"eq:rBInfty\"></a>(13)\n",
      "$$\n",
      "r_B=S+\\frac{1}{\\alpha}\\,\\log\\left(\\frac{\\tilde \\omega-(q+1)^2}{\\tilde \\omega-q^2}\\right),\n",
      "$$\n",
      "\n",
      "where\n",
      "\n",
      "$$\n",
      "\\tilde \\omega=\\frac{2\\,\\omega}{\\alpha^2\\,\\sigma^2}=:(q_{\\max}+1)^2.\n",
      "$$\n",
      "\n",
      "Similarly\n",
      "\n",
      "<a name=\"eq:rAInfty\"></a>(14)\n",
      "$$\n",
      "r_A=S-\\frac{1}{\\alpha}\\,\\log\\left(\\frac{\\tilde \\omega-(q-1)^2}{\\tilde \\omega-q^2}\\right).\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Small inventory limit\n",
      "\n",
      "In the limit of small inventory $|q| \\ll q_{\\max}$, [(13)](#eq:rBInfty) and [(14)](#eq:rAInfty) become\n",
      "\n",
      "$$\n",
      "r_B \\approx r^\\star -s/2 ;\\, r_A \\approx r^\\star +s/2\n",
      "$$\n",
      "\n",
      "with\n",
      "\n",
      "\\begin{eqnarray*}\n",
      "s/2 & \\approx & \\frac{1}{\\alpha\\,q_{\\max}^2}, \\\\\n",
      "r^\\star & \\approx & S -2\\,q\\,\\frac{1}{\\alpha\\,q_{\\max}^2}=S-q\\,s. \n",
      "\\end{eqnarray*}"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Fair price $P$\n",
      "\n",
      "- We may repeat the foregoing analysis with the current stock price $S$ replaced with the market maker's private valuation $P$ (which we may think of as the fair price of the stock).\n",
      "    - $P$ may be estimated by observing the state of the order book.\n",
      "    - $\\lambda_A$ and $\\lambda_B$ may be estimated using the autocorrelation of order flow.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Symmetric exponential arrival rates\n",
      "\n",
      "Following Avellaneda and Stoikov, suppose that\n",
      "\n",
      "$$\n",
      "\\lambda^A(\\delta)=\\lambda^B(\\delta) = A\\,e^{-k\\,\\delta}.\n",
      "$$\n",
      "\n",
      "- This is a questionable approximation because arrival rates probably depend on inventory.\n",
      "    - Adverse selection again!\n",
      "\n",
      "\n",
      "- However, making this approximation gives the same expression for the indifference price as the \"frozen inventory\" indifference price [(8)](#eq:reservationPrice) and simplifies the analysis.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Solution of Avellaneda-Stoikov HJB equation\n",
      "\n",
      "The HJB equation [(10)](#eq:HJBAS2) looks impossible to solve. However, by assuming exponential arrival of limit orders and expanding for small $q$, [Avellaneda and Stoikov]<sup id=\"cite_ref-AvellanedaStoikov\" class=\"reference\"><a href=\"#cite_note-AvellanedaStoikov\">[1]</a></sup> get\n",
      "\n",
      "$$\n",
      "r^\\star=S-q\\,\\alpha\\,\\sigma^2\\,(T-t)\n",
      "$$\n",
      "\n",
      "with \n",
      "\n",
      "$$\n",
      "\\delta_A+\\delta_B=\\alpha\\,\\sigma^2\\,(T-t)+\\frac{2}{\\alpha}\\,\\log\\left(1+\\frac{\\alpha}{k}\\right).\n",
      "$$\n",
      "\n",
      "- Set the reservation price $r^\\star$.\n",
      "\n",
      "\n",
      "- Make a spread around this price."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Results of simulation\n",
      "\n",
      "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/AShistogram.png\" align = \"center\" width=500></h2>\n",
      "\n",
      "#### Note\n",
      "$\\gamma$ is, in our notation, $\\alpha$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### An exact solution of the HJB equation\n",
      "\n",
      "- [Gu&eacute;ant, Lehalle and Fernandez-Tapia]<sup id=\"cite_ref-GFL\" class=\"reference\"><a href=\"#cite_note-GFL\">[4]</a></sup> later came up with a clever way of solving the HJB equation [(10)](#eq:HJBAS2) assuming exponential market order arrival rates $\\lambda^A(\\delta) = \\lambda^B(\\delta) = A e^{ \u2212k \\delta}$.\n",
      "\n",
      "\n",
      "- The key trick is to impose inventory limits so that $q \\in [\u2212Q,Q]$. Then, by solving a system of ODEs indexed $q$, they can solve the problem in closed-form.\n",
      "\n",
      "\n",
      "- They obtain\n",
      "\n",
      "    \\begin{eqnarray*}\n",
      "    \\delta_B &=& \\frac 1k\\, \\log \\frac{v_q(T)}{v_{q+1}(T)}+\\frac{1}{\\alpha}\\,\\log\\left(1+\\frac{\\alpha}{k}\\right) \\\\\n",
      "    && \\\\\n",
      "    \\delta_A &=&  \\frac 1k \\,\\log \\frac{v_q(T)}{v_{q-1}(T)}+\\frac{1}{\\alpha}\\,\\log\\left(1+\\frac{\\alpha}{k}\\right)\n",
      "    \\end{eqnarray*}\n",
      "    \n",
      "    where the $v_q(\\cdot)$ are solutions of the aforementioned system of ODEs."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Improved asymptotics\n",
      "\n",
      "- Contrary to the conclusion drawn by [Avellaneda and Stoikov]<sup id=\"cite_ref-AvellanedaStoikov\" class=\"reference\"><a href=\"#cite_note-AvellanedaStoikov\">[1]</a></sup> from their asymptotic analysis, [Gu&eacute;ant, Lehalle and Fernandez-Tapia]<sup id=\"cite_ref-GFL\" class=\"reference\"><a href=\"#cite_note-GFL\">[4]</a></sup> show that the optimal quotes are almost independent of $T$ if time remaining $(T)$ is big enough.\n",
      "\n",
      "\n",
      "- With a heuristic argument and assuming $q$ small, [Gu&eacute;ant, Lehalle and Fernandez-Tapia]<sup id=\"cite_ref-GFL\" class=\"reference\"><a href=\"#cite_note-GFL\">[4]</a></sup> propose the following asymptotic approximation:\n",
      "\n",
      "    \\begin{eqnarray*}\n",
      "    \\delta_B &=& \\frac{1}{\\alpha}\\,\\log\\left(1+\\frac{\\alpha}{k}\\right)+(q+1/2)\\,\\sqrt{\\frac{\\sigma^2\\,\\alpha}{2\\,k\\,A}\\,\\left(1+\\frac \\alpha k\\right)^{1+k/\\alpha}} \\\\\n",
      "    && \\\\\n",
      "    \\delta_A &=&  \\frac{1}{\\alpha}\\,\\log\\left(1+\\frac{\\alpha}{k}\\right)-(q-1/2)\\,\\sqrt{\\frac{\\sigma^2\\,\\alpha}{2\\,k\\,A}\\,\\left(1+\\frac \\alpha k\\right)^{1+k/\\alpha}}\n",
      "    \\end{eqnarray*}\n",
      "    \n",
      "    which are of course independent of $T$."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Adding market orders\n",
      "\n",
      "- The frameworks of both [Avellaneda and Stoikov]<sup id=\"cite_ref-AvellanedaStoikov\" class=\"reference\"><a href=\"#cite_note-AvellanedaStoikov\">[1]</a></sup> and [Gu&eacute;ant, Lehalle and Fernandez-Tapia]<sup id=\"cite_ref-GFL\" class=\"reference\"><a href=\"#cite_note-GFL\">[4]</a></sup> assume that the market maker\u2019s problem is to place limit orders optimally so as to maximize utility assuming Poisson arrivals of market orders.\n",
      "    - The optimal limit price could easily be outside the current spread.\n",
      "\n",
      "\n",
      "- In practice, it could obviously be optimal for the market maker to sometimes cross the spread and send market orders to reduce inventory.\n",
      "\n",
      "\n",
      "- In the more realistic setup of [Guilbaud and Pham]<sup id=\"cite_ref-GPham\" class=\"reference\"><a href=\"#cite_note-GPham\">[5]</a></sup>, the market maker may post limit orders at the best bid and offer prices, improve the spread, or send market orders.\n",
      "    - Market order arrival rates are allowed to be time-dependent (as they are in practice).\n",
      "    - Market order arrival rates are additionally (real-time estimated) functions of the spread."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Guilbaud and Pham solution\n",
      "\n",
      "- The resulting HJB equation is discretized and solved numerically.\n",
      "    - Obviously too complicated to solve analytically.\n",
      "\n",
      "\n",
      "- Pseudo-code is provided to facilitate implementation of the algorithm.\n",
      "\n",
      "\n",
      "- The algorithm is tested on simulated data and compared with the following three strategies:\n",
      "    - WoMO: Same strategy with no market orders\n",
      "    - Cst: Place constant quantities on each of the best quotes\n",
      "    - Place constant quantity on each side at random prices that are at the best quote or improve the spread.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Guilbaud and Pham simulation results\n",
      "\n",
      "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/GPsimResults.png\" align = \"center\" width=500></h2>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Guilbaud and Pham optimal frontier\n",
      "\n",
      "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/GPoptimalFrontier.png\" align = \"center\" width=600></h2>\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### Final remarks\n",
      "\n",
      "- All inventory models have the following characteristics:\n",
      "    - It is optimal for the market maker to keep inventory close to zero.\n",
      "    - There will therefore be mean reversion in prices due to inventory effects.\n",
      "    - The spread is compensation for risk.\n",
      "    - Biasing prices to encourage liquidation of inventory reduces the variance of returns.\n",
      "        - This also causes short-term mean reversion in prices.\n",
      "\n",
      "\n",
      "- In real markets, as in [Guilbaud and Pham]<sup id=\"cite_ref-GPham\" class=\"reference\"><a href=\"#cite_note-GPham\">[5]</a></sup>, the spread is given.\n",
      "    - A market maker either joins or improves the best quote, or does no business.\n",
      "\n",
      "\n",
      "- However, market order arrival rates are not symmetric: they depend on the book imbalance $\\mathcal{I}$.\n",
      "    - This  work remains to be done!\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "### References\n",
      "\n",
      "<br />\n",
      "\n",
      "<div class=\"reflist\" style=\"list-style-type: decimal;\">\n",
      "\n",
      "<ol>\n",
      "\n",
      "  <li id=\"cite_note-AvellanedaStoikov\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AvellanedaStoikov\">^</a></b></span> Marco Avellaneda and Sasha Stoikov, High-frequency trading in a limit order book, <span>*Quantitative Finance*</span> <span>**8**</span>(3), 217\u2013224, (2008).</li>\n",
      "\n",
      "  \n",
      "  <li id=\"cite_note-FS\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-FS\">^</a></b></span> Hans F&ouml;llmer  and Alexander Schied, *Stochastic Finance: An Introduction in Discrete Time*, De Gruyter, Berlin (2011). </li>\n",
      "\n",
      "  \n",
      "  <li id=\"cite_note-GabaixEtAl\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GabaixEtAl\">^</a></b></span>   Xavier Gabaix, Parameswaran Gopikrishnan, Vasiliki Plerou and  H. Eugene Stanley,  Understanding the cubic and half-cubic laws of financial fluctuations, <span>*Physica A: Statistical Mechanics and its Applications*</span> <span>**324**</span>(1-2), 1-5, (2003).</li>\n",
      "\n",
      "  \n",
      "  <li id=\"cite_note-GLF\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GLF\">^</a></b></span> Olivier Gu&eacute;ant, Charles-Albert Lehalle, and Joaquin Fernandez-Tapia, Dealing with the inventory risk: a solution to the market making problem, <span>*Mathematics and Financial Economics*</span> <span>**7**</span>(4), 477-507, (2013). </li>\n",
      "\n",
      "  <li id=\"cite_note-GPham\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GPham\">^</a></b></span> Fabien Guilbaud and Huy&ecirc;n Pham, Optimal high-frequency trading with limit and market orders, <span>*Quantitative Finance*</span> <span>**13**</span>(1), 79-94, (2013). </li>\n",
      "  \n",
      "  <li id=\"cite_note-Hasbrouck\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Hasbrouck\">^</a></b></span>   Joel Hasbrouck, <span>*Empirical Market Microstructure*</span>, Oxford\n",
      "University Press, Chapter 11, (2007).</li>\n",
      "\n",
      "  <li id=\"cite_note-Menkveld\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Menkveld\">^</a></b></span>   Albert J Menkveld, High frequency trading and the new-market makers, <span>**SSRN**</span>, (2012).</li>\n",
      "\n",
      "</ol>"
     ]
    }
   ],
   "metadata": {}
  }
 ]
}